package com.dbf.forum.dao.offre;

import java.util.List;

import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;

import com.dbf.forum.common.dao.CommonDaoJpa;
import com.dbf.forum.core.offre.Offre;

@Repository(value="offreDao")
public class OffreDaoJpa extends CommonDaoJpa implements OffreDao{
	
	public List<Offre> getOffresByUser(Long userId){
		String q = "select off from Off offre join off.acheteur ach where ach.id = "+userId+"";
		TypedQuery<Offre> query = createQuery(Offre.class, q);
		List<Offre> offres = query.getResultList();
		if(offres.isEmpty()){
			return null;
		}
		return offres;
	}
	
	public List<Offre> getOffresByUserAndProduits(Long userId){
		String q = "select off from Offre off where off.produit.vendeur.id = "+userId+"";
		TypedQuery<Offre> query = createQuery(Offre.class, q);
		List<Offre> offres = query.getResultList();
		if(offres.isEmpty()){
			return null;
		}
		return offres;
	}
}
